#ifndef __json_reader
#define __json_reader

#include "rapidjson/reader.h"
#include <iostream>
#include <cstdlib>
#include "websocket.h"
#include <string_view>

using namespace rapidjson;
using namespace std;
 
struct MyHandler : public BaseReaderHandler<UTF8<>, MyHandler> {
    
    private: 
    bool start_data_type_token{false};

    public:
    std::string_view  data_type_view;

    bool Null() {  return true; }
    bool Bool(bool b) { return true; }
    bool Int(int i) { return true; }
    bool Uint(unsigned u) {  return true; }
    bool Int64(int64_t i) {  return true; }
    bool Uint64(uint64_t u) { return true; }
    bool Double(double d) { return true; }
    bool String(const char* str, SizeType length, bool copy) { 
       if(start_data_type_token){
         start_data_type_token=false;
        data_type_view=std::string_view (str,length);
       return false;
        }
    return true;


       
    }
    bool StartObject() { 
    
    return true; }
    bool Key(const char* str, SizeType length, bool copy) { 
        //   DHS_LOG("MyHandler---key---%s\n",str);

        if(strncmp(str,data_type,length)==0){
         start_data_type_token=true;
        }
       
           return true;
      
    }
    bool EndObject(SizeType memberCount) {  return true; }
    bool StartArray() { return true; }
    bool EndArray(SizeType elementCount) { 

       return true; }
};

#endif